package dp;
import java.io.*;
import java.util.*;
public class _08_kama_46_01背包 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static int N = 5010;
	static int n,m;
	static int weight[] = new int[N];
	static int value[] = new int[N];
	static int dp[][] = new int[N][N];
	static StringTokenizer st;
	public static void main(String[] args) throws IOException {
		st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		m = Integer.parseInt(st.nextToken());
		
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			weight[i] = Integer.parseInt(st.nextToken());
		}
		st = new StringTokenizer(br.readLine());
		for(int i = 1; i <= n; i++) {
			value[i] = Integer.parseInt(st.nextToken());
		}
		int res = 0;
		for(int i = 1; i <= n; i++) { // 物品
			for(int j = 1; j <= m; j++) { // 容积
				if(weight[i] > j) {
					dp[i][j] = dp[i-1][j];
				} else {
					dp[i][j] = Math.max(dp[i-1][j], dp[i-1][j-weight[i]] + value[i]);
				}
				res = Math.max(res, dp[i][j]);
			}
		}
				
		System.out.println(res);
	}
}
